package czy.demo.endpoint;

import czy.demo.service.Country;
import czy.demo.service.Currency;
import czy.demo.service.GetCountryRequest;
import czy.demo.service.GetCountryResponse;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

/* 端点为webservice的对外接口 */
@Endpoint
public class CountryEndpoint {

    /* 命名空间，需要和xsd里的targetNamespace相同 */
    private static final String NAMESPACE_URI = "http://www.dexcoder.com/ws";

    /* 一个端点可以有多个接口，接口使用localPart区分，localPart与xsd里element的name对应？ */

    /**
     * 端点方法的请求响应都必须和xsd里的element对应，这样才能使用jaxb来解析xml内容为对象
     */
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
    @ResponsePayload
    public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
        GetCountryResponse response = new GetCountryResponse();
        Country poland = new Country();
        poland.setName("Poland-" + request.getName());
        poland.setCapital("Warsaw");
        poland.setCurrency(Currency.PLN);
        poland.setPopulation(38186860);
        response.setCountry(poland);
        return response;
    }
}